package com.brspace.qualitycontrol.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.MeetNotice;
import com.brspace.qualitycontrol.entity.NewNotice;
import com.brspace.qualitycontrol.entity.Publish;
import com.brspace.qualitycontrol.entity.vo.NoticeTypeVo;
import com.brspace.qualitycontrol.entity.vo.NoticeVo;
import com.brspace.qualitycontrol.entity.vo.PaginationVo;
import com.brspace.qualitycontrol.service.MeetNoticeService;
import com.brspace.qualitycontrol.service.NewNoticeService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 新建通知 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Api(description = "新建通知")
@CrossOrigin
@RestController
@RequestMapping("/admin/new-notice")
public class NewNoticeController {

    @Resource
    private NewNoticeService newNoticeService;
    @Resource
    private MeetNoticeService meetNoticeService;

    /**
     * 新建新闻通知
     * @param newNotice
     * @return
     */
    @ApiOperation("新建通知")
    @PostMapping("addNew")
    public R addNew( NewNotice newNotice){
        newNotice.setNoticeType("通知");
        return  newNoticeService.addNew(newNotice);
    }

    @ApiOperation("全部通知")
    @GetMapping("list")
    public R list(){
        List<NewNotice> list = newNoticeService.list(null);
        return R.ok().data("list",list);
    }

    @ApiOperation(value = "分页查询会议和通知消息", notes = "分页查询会议和通知消息")
    @PostMapping("getNoticeList")
    public R findInStockList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize") Integer pageSize){
        PaginationVo<NoticeTypeVo> noticePage = newNoticeService.selectAllList(pageNum,pageSize);
        return R.ok().data("total",noticePage.getTotal()).data("rows",noticePage.getDataList());
    }

    @ApiOperation(value = "查询指定日期的会议或通知消息", notes = "查询指定日期的会议或通知消息")
    @PostMapping("getDayList")
    public R getDayList(NewNotice newNotice){
        List<NoticeVo> list = meetNoticeService.getDayList(newNotice.getNoticeDate());
        List<NoticeVo> list1 = newNoticeService.getDayList(newNotice.getNoticeDate());
        list.addAll(list1);
        return R.ok().data("list",list);
    }

    @ApiOperation(value = "获取今天之后有会议或通知的日期", notes = "获取今天之后有会议或通知的日期")
    @PostMapping("getNoticeAfter")
    public R getNoticeAfter(){
        List<String> list = meetNoticeService.getNoticeAfter();
        List<String> list1 = newNoticeService.getNoticeAfter();
        list.addAll(list1);
        return R.ok().data("list",list);
    }

    @ApiOperation(value = "根据id查询通知详情", notes = "根据id查询通知详情")
    @PostMapping("selectById")
    public R selectById(NewNotice newNotice){
        NewNotice byId = newNoticeService.getById(newNotice.getId());
        return R.ok().data("data",byId);
    }
}

